package com.zzb.servlet.producttype;

import com.alibaba.fastjson.JSONObject;
import com.zzb.DTO.ResultDTO;
import com.zzb.VO.ProductTypeVO;
import com.zzb.service.ProductTypeService;
import com.zzb.service.impl.ProductTypeServiceImpl;
import com.zzb.util.Tool;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/back/product/type/all")
public class ProductTypeFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
//乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        //得到前端数据
        String isShow = req.getParameter("isShow");
        String enable = req.getParameter("enable");
        String name = req.getParameter("name");
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");

        //对前端数据进行封装
        ProductTypeVO productTypeVO = new ProductTypeVO();
        productTypeVO.setIsShow(Integer.valueOf(Tool.nullToNum(isShow)));
        productTypeVO.setName(Tool.nullToStr(name));
        productTypeVO.setEnable(Integer.valueOf(Tool.nullToNum(enable)));
        productTypeVO.setPage(Integer.valueOf(Tool.nullToNum(page)));
        productTypeVO.setLimit(Integer.valueOf(Tool.nullToNum(limit)));

        //调用服务逻辑
        ProductTypeService productTypeService = new ProductTypeServiceImpl();

        //得到返回值
        ResultDTO resultDTO = productTypeService.findAll(productTypeVO);
        //响应
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
